package com.cn.hjsj.util;

public class GeoUitl {  
	private final static double PI = 3.14159265358979323; //圆周率
	private final static double R = 6371229;             //地球的半径
    /**  
     * 转化为弧度(rad)  
     * */    
    private static double rad(double d)    
    {    
       return d * Math.PI / 180.0;    
    } 
    
    public static double GetDistance(double lon1,double lat1,double lon2, double lat2)    
    {    
       double radLat1 = rad(lat1);    
       double radLat2 = rad(lat2);    
       double a = radLat1 - radLat2;    
       double b = rad(lon1) - rad(lon2);    
       double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2)+Math.cos(radLat1)*Math.cos(radLat2)*Math.pow(Math.sin(b/2),2)));    
       s = s * R;    
       s = Math.round(s * 10000) / 10000;    
       return s;    
    }
	/**
	* 距离转换成经度
	* @param distance 和中心点的纬度
	* @return
	*/
    public static double doLngDegress(long distance,double wd) {
		double lngDegree = 2 * Math.asin(Math.sin((double)distance/(2*R))/Math.cos(wd*PI/180));
		// 转换弧度
		lngDegree = lngDegree * (180/Math.PI);
		return Math.abs(lngDegree);
	}
	/**
	* 距离转换成纬度
	* @param distance
	* @return
	*/
    public static double doLatDegress(long distance) {
		double latDegrees = (double)distance/R;
		// 转换弧度
		latDegrees = latDegrees * (180/Math.PI);
		//return Math.abs(latDegrees);
		return Math.abs(latDegrees);
	}
//	public static void main(String[] args) {
//		
//		double jd =120.1548141133;
//        double wd =120.1548141133;
//        long distance = 4000;
//        double jd1 =doLngDegress(distance,wd);
//        double wd1 =doLatDegress(distance);
//        System.out.println(jd1);
//        System.out.println(wd1);
//        System.out.println(GetDistance(jd,wd,jd+jd1,wd));
//        System.out.println(GetDistance(jd,wd,jd,wd+wd1));
//        System.out.println(GetDistance(jd,wd,jd-jd1,wd));
//        System.out.println(GetDistance(jd,wd,jd,wd-wd1));     
//	}
}  
